package com.bili.bili_data_api.service.impl;

import com.bili.bili_data_api.dao.mapper.*;
import com.bili.bili_data_api.dao.pojo.*;
import com.bili.bili_data_api.service.WeekService;
import com.bili.bili_data_api.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class WeekServiceImpl implements WeekService {
    @Autowired
    WeeklyTypeMapper weeklyTypeMapper;

    @Autowired
    ViewTop10Mapper viewTop10Mapper;

    @Autowired
    FavourTop10Mapper favourTop10Mapper;

    @Autowired
    CoinTop10Mapper coinTop10Mapper;

    @Autowired
    LabelTopMapper labelTopMapper;

    @Autowired
    ViewTongJiMapper viewTongJiMapper;

    @Override
    public WeeklytypeVo getAllWeeklyType() {
        List<Weeklytype> weeklytypes = weeklyTypeMapper.selectList(null);
        List<String> type = new ArrayList<>();
        List<String> num = new ArrayList<>();
        WeeklytypeVo weeklytypeVo = new WeeklytypeVo();
        int i=0;
        for (Weeklytype weeklytype : weeklytypes) {
            type.add(weeklytype.getStyle());
            num.add(weeklytype.getNum());
            i++;
            if (i==15) break;
        }
        weeklytypeVo.setNum(num);
        weeklytypeVo.setType(type);
        return weeklytypeVo;
    }

    @Override
    public ViewTop10Vo getAllViewTop10() {
        List<Viewtop10> viewtop10s = viewTop10Mapper.selectList(null);
        List<String> title = new ArrayList<>();
        List<String> view = new ArrayList<>();
        ViewTop10Vo viewTop10Vo=new ViewTop10Vo();
        for (Viewtop10 viewtop10 : viewtop10s) {
            title.add(viewtop10.getTitle());
            view.add(viewtop10.getView());
        }
        Collections.reverse(title);
        Collections.reverse(view);
        viewTop10Vo.setTitle(title);
        viewTop10Vo.setView(view);
        return viewTop10Vo;
    }

    @Override
    public Favourtop10Vo getAllFavourtop10() {
        List<Favourtop10> favourtop10s = favourTop10Mapper.selectList(null);
        List<String> title = new ArrayList<>();
        List<String> favour = new ArrayList<>();
        Favourtop10Vo favourtop10Vo = new Favourtop10Vo();
        for (Favourtop10 favourtop10 : favourtop10s) {
            title.add(favourtop10.getTitle());
            favour.add(favourtop10.getFavour());
        }
        Collections.reverse(title);
        Collections.reverse(favour);
        favourtop10Vo.setTitle(title);
        favourtop10Vo.setFavour(favour);
        return favourtop10Vo;
    }

    @Override
    public CoinTop10Vo getAllCoinTop10() {
        List<Cointop10> cointop10s = coinTop10Mapper.selectList(null);
        List<String> title = new ArrayList<>();
        List<String> coin = new ArrayList<>();
        CoinTop10Vo coinTop10Vo = new CoinTop10Vo();
        for (Cointop10 cointop10 : cointop10s) {
            title.add(cointop10.getTitle());
            coin.add(cointop10.getCoin());
        }
        Collections.reverse(title);
        Collections.reverse(coin);
        coinTop10Vo.setTitle(title);
        coinTop10Vo.setCoin(coin);
        return coinTop10Vo;
    }

    @Override
    public LabelTopVo getAllLabelTop() {
        List<Labeltop> labeltops = labelTopMapper.selectList(null);
        List<String> labelTitle = new ArrayList<>();
        List<String> view = new ArrayList<>();
        LabelTopVo labelTopVo = new LabelTopVo();
        for (Labeltop labeltop : labeltops) {
            labelTitle.add(labeltop.getLabel()+labeltop.getTitle());
            view.add(labeltop.getView());
        }
        Collections.reverse(labelTitle);
        Collections.reverse(view);
        labelTopVo.setLabelTitle(labelTitle);
        labelTopVo.setView(view);
        return labelTopVo;
    }

    @Override
    public ViewTongJiVo getViewTongJivo() {
        List<Viewtongji> viewtongjis = viewTongJiMapper.selectList(null);
        ViewTongJiVo viewTongJiVo = new ViewTongJiVo();
        List<Over> overs = new ArrayList<>();
        for (Viewtongji viewtongji : viewtongjis) {
            Over over = new Over();
            over.setName(viewtongji.getTitle());
            over.setValue(viewtongji.getNum());
            overs.add(over);
        }
        viewTongJiVo.setViewTongJi(overs);
        return viewTongJiVo;
    }
}
